package com.teddy.model;

import java.util.HashMap;

import com.teddy.model.BaseDTO;

public class Database {
	BaseDTO root;
	private HashMap<String, BaseDTO> db = new HashMap<String, BaseDTO>();
	
	public Database() {
		root = new BaseDTO("root", "root");
		getDb().put(root.getURI(), root);
		init();
	}
	
	private void init() {
		for (int i = 0; i < 2; i++) {
			
			reccursiveItemCreation(root, 2, 2, "Item." + (i+1));
		}
	}
	
	private void reccursiveItemCreation(BaseDTO parent, int noOfSublevels, int noOfNodes, String name) {
		BaseDTO item = new BaseDTO( name, name);
		getDb().put(item.getURI(), item);
		if( noOfSublevels > 0) {
			for (int i = 0; i < noOfNodes; i++) {
				reccursiveItemCreation(item, noOfSublevels - 1, noOfNodes, name + "."+ (i+1));
			}
		}
		parent.getNarrowerMap().put(name, item);
	}
	
	public void setRoot(BaseDTO root) {
		this.root = root;
	}

	public BaseDTO getRoot() {
		return root;
	}

	public void setDb(HashMap<String, BaseDTO> db) {
		this.db = db;
	}

	public HashMap<String, BaseDTO> getDb() {
		return db;
	}
}
